package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.CrmUser;
import com.ruoyi.system.domain.CrmUserRecord;
import com.ruoyi.system.mapper.CrmUserMapper;
import com.ruoyi.system.mapper.CrmUserRecordMapper;
import com.ruoyi.system.service.ICrmUserRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-10-14
 */
@Service
public class CrmUserRecordServiceImpl implements ICrmUserRecordService 
{
    @Autowired
    private CrmUserRecordMapper crmUserRecordMapper;
    @Autowired
    private CrmUserMapper crmUserMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public CrmUserRecord selectCrmUserRecordById(Long id)
    {
        return crmUserRecordMapper.selectCrmUserRecordById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param CrmUserRecord 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<CrmUserRecord> selectCrmUserRecordList(CrmUserRecord CrmUserRecord)
    {
        return crmUserRecordMapper.selectCrmUserRecordList(CrmUserRecord);
    }


    public List<CrmUserRecord> selectCrmUserRecordListByNextTime(Long createUser){
        return crmUserRecordMapper.selectCrmUserRecordListByNextTime(createUser);

    }

    @Override
    public List<CrmUserRecord> selectCrmUserRecordListByTime(Date startTime, Date endTime, Long userId){

        return crmUserRecordMapper.selectCrmUserRecordListByTime(startTime,endTime,userId);

    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param crmUserRecord 【请填写功能名称】
     * @return 结果
     */
    @Override
    @Transactional
    public int insertCrmUserRecord(CrmUserRecord crmUserRecord)
    {
        int i=crmUserRecordMapper.insertCrmUserRecord(crmUserRecord);
        CrmUser crmUser=crmUserMapper.selectCrmUserById(crmUserRecord.getCusId());
        if(crmUser!=null){
            crmUser.setUpdateTime(new Date());
            crmUser.setLastRecordId(crmUserRecord.getId());
            crmUserMapper.updateCrmUser(crmUser);
        }
        return i;
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param CrmUserRecord 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateCrmUserRecord(CrmUserRecord CrmUserRecord)
    {
        return crmUserRecordMapper.updateCrmUserRecord(CrmUserRecord);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteCrmUserRecordByIds(Long[] ids)
    {
        return crmUserRecordMapper.deleteCrmUserRecordByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteCrmUserRecordById(Long id)
    {
        return crmUserRecordMapper.deleteCrmUserRecordById(id);
    }
}
